# -*-coding:utf-8 -*-
from rest_framework import permissions


class ExtModelPermissions(permissions.DjangoModelPermissions):
    perms_map = {
        'GET': ['%(app_label)s.view_%(model_name)s', '%(app_label)s.viewall_%(model_name)s'],
        'OPTIONS': [],
        'HEAD': [],
        'POST': ['%(app_label)s.add_%(model_name)s'],
        'PUT': ['%(app_label)s.change_%(model_name)s'],
        'PATCH': ['%(app_label)s.change_%(model_name)s'],
        'DELETE': ['%(app_label)s.delete_%(model_name)s'],
    }


class OwnerModelPermissions(permissions.DjangoObjectPermissions):

    def has_permission(self, request, view):
        queryset = self._queryset(view)
        model_cls = queryset.model
        request.user.has_perms("")
        result = super(OwnerModelPermissions, self).has_permission(request, view)
